//
//
//  机头当前角度
//
//


import QtQuick
import QtQuick.Controls.Basic

Item {
    id: mechineAngleRoot
    width: rootWidth
    height: 650

    Rectangle{
        anchors.fill: parent
        border.width: 3
        border.color: "#F8F8FF"
        color: "transparent"
    }    


    Item{
        id: leftMechineAngle
        anchors.top: mechineAngleRoot.top
        anchors.topMargin: 100
        anchors.left: mechineAngleRoot.left
        anchors.leftMargin: 110
        width: 280
        height: 280
        // visible: !Cpp_PLC.M_530

        Rectangle{
            width: 60
            height: 60
            radius: 30
            anchors.left: leftMechineAngle.left
            // anchors.leftMargin: 80
            anchors.top: leftMechineAngle.top
            anchors.topMargin: 10
            z:99
            color: Cpp_PLC.IO_X14 ? "red" : "white"
        }

        Rectangle{
            width: 60
            height: 60
            radius: 30
            anchors.right: leftMechineAngle.right
            // anchors.leftMargin: 380
            anchors.top: leftMechineAngle.top
            anchors.topMargin: 10
            z:99
            color: Cpp_PLC.IO_X12 ? "red" : "white"
        }

        state: Cpp_PLC.LeftAngleFeedBack ? "Default" : "-45rotated"

        states: [
            State {
                name: "45rotated"
                PropertyChanges {
                    target: leftMechineAngle
                    rotation : 45
                }
            },
            State {
                name: "Default"
                PropertyChanges {
                    target: leftMechineAngle
                    rotation : 0
                }
            },
            State {
                name: "-45rotated"
                PropertyChanges {
                    target: leftMechineAngle
                    rotation : -45
                }
            }
        ]

        transitions: Transition {
            PropertyAnimation{
                target: leftMechineAngle
                property: "rotation"
                duration: 500
                easing.type: Easing.InOutQuad
            }
        }

        Rectangle{
            anchors.fill: parent
            color: "gold"

            Rectangle{
                width: 3
                height: parent.height * 0.8
                anchors.centerIn: parent
            }
        }
    }

    Item{
        anchors.top: leftMechineAngle.bottom
        anchors.topMargin: 80
        anchors.horizontalCenter: leftMechineAngle.horizontalCenter
        width: 400
        height: 230
        visible: !Cpp_PLC.M_530

        A_Button{
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: "45°"
            contentText_Fontsize: 35
            contentText_Bold: false

            onButtonClicked: {
                // leftMechineAngle.state = "45rotated"
            }

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(13,"1");
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(13,"0");
            }

        }

        A_Button{
            anchors.top: parent.top
            anchors.topMargin: 80
            anchors.horizontalCenter: parent.horizontalCenter
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: "90°"
            contentText_Fontsize: 35
            contentText_Bold: false

            onButtonClicked: {
                // leftMechineAngle.state = "90rotated"
            }

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(15,"1");
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(15,"0");
            }

        }

        // A_Button{
        //     anchors.top: parent.top
        //     anchors.topMargin: 160
        //     anchors.horizontalCenter: parent.horizontalCenter
        //     buttonWidth: 200
        //     buttonHeight: 60
        //     contentText_Data: "-45°"
        //     contentText_Fontsize: 35
        //     contentText_Bold: false

        //     onButtonClicked: {
        //         leftMechineAngle.state = "-45rotated"
        //     }

        // }

    }


    Item{
        anchors.horizontalCenter: mechineAngleRoot.horizontalCenter
        anchors.bottom: mechineAngleRoot.bottom
        anchors.bottomMargin: 50
        width: 280
        height: 220

        A_Button{
            id: leftSawSingleOut
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            // anchors.horizontalCenterOffset: 30
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: qsTr("左锯出锯")
            contentText_Fontsize: Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
            contentText_Bold: false
            contentRectangle_BorderWidth: Cpp_PLC.SawsMode === "1" ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.SawsMode === "1" ? "gold" : "black"

            onButtonClicked: {
                // console.log("左锯片出锯")
                Cpp_PLC.write_Modbus_RTU_Hold_16(229,"1")
            }

        }

        // Rectangle{
        //     anchors.verticalCenter: leftSawSingleOut.verticalCenter
        //     anchors.right: leftSawSingleOut.left
        //     anchors.rightMargin: 5
        //     width: 30
        //     height: 60
        //     radius: 10
        //     color: Cpp_PLC.SawsMode === "1" ? "green" : "black"
        //     border.width: 1
        //     border.color: "white"
        //     // visible: Cpp_PLC.SawsMode === "1" ? true : false
        // }

        A_Button{
            id: bothSawsOut
            anchors.top: parent.top
            anchors.topMargin: 80
            anchors.horizontalCenter: parent.horizontalCenter
            // anchors.horizontalCenterOffset: 30
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: qsTr("左右联动")
            contentText_Fontsize: Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
            contentText_Bold: false
            contentRectangle_BorderWidth: Cpp_PLC.SawsMode === "0" ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.SawsMode === "0" ? "gold" : "black"

            onButtonClicked: {
                console.log("联动出锯")
                Cpp_PLC.write_Modbus_RTU_Hold_16(229,"0")
            }

        }

        // Rectangle{
        //     anchors.verticalCenter: bothSawsOut.verticalCenter
        //     anchors.right: bothSawsOut.left
        //     anchors.rightMargin: 5
        //     width: 30
        //     height: 60
        //     radius: 10
        //     color: Cpp_PLC.SawsMode === "0" ? "green" : "black"
        //     border.width: 1
        //     border.color: "white"
        // }

        A_Button{
            id: rightSawSingleOut
            anchors.top: parent.top
            anchors.topMargin: 160
            anchors.horizontalCenter: parent.horizontalCenter
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: qsTr("右锯出锯")
            contentText_Fontsize: Cpp_Config.Language_Type === 1 ? 35 :  Cpp_Config.Language_Type === 2 ? 20 : 20
            contentText_Bold: false
            contentRectangle_BorderWidth: Cpp_PLC.SawsMode === "2" ? 5 : 3
            contentRectangle_BorderColor: Cpp_PLC.SawsMode === "2" ? "gold" : "black"

            onButtonClicked: {
                console.log("右锯片出锯")
                Cpp_PLC.write_Modbus_RTU_Hold_16(229,"2")
            }

        }

        // Rectangle{
        //     anchors.verticalCenter: rightSawSingleOut.verticalCenter
        //     anchors.right: rightSawSingleOut.left
        //     anchors.rightMargin: 5
        //     width: 30
        //     height: 60
        //     radius: 10
        //     color: Cpp_PLC.SawsMode === "2" ? "green" : "black"
        //     border.width: 1
        //     border.color: "white"
        // }

    }






    Item{
        id: rightMechineAngle
        anchors.top: mechineAngleRoot.top
        anchors.topMargin: 100
        anchors.right: mechineAngleRoot.right
        anchors.rightMargin: 110
        width: 280
        height: 280
        // visible: !Cpp_PLC.M_530

        Rectangle{
            width: 60
            height: 60
            radius: 30
            anchors.left: rightMechineAngle.left
            // anchors.leftMargin: 80
            anchors.top: rightMechineAngle.top
            anchors.topMargin: 10
            z:99
            color: Cpp_PLC.IO_X15 ? "red" : "white"
        }

        Rectangle{
            width: 60
            height: 60
            radius: 30
            anchors.right: rightMechineAngle.right
            // anchors.leftMargin: 380
            anchors.top: rightMechineAngle.top
            anchors.topMargin: 10
            z:99
            color: Cpp_PLC.IO_X13 ? "red" : "white"
        }

        state: Cpp_PLC.RightAngleFeedBack ? "Default" : "-45rotated"

        states: [
            State {
                name: "45rotated"
                PropertyChanges {
                    target: rightMechineAngle
                    rotation : -45
                }
            },
            State {
                name: "Default"
                PropertyChanges {
                    target: rightMechineAngle
                    rotation : 0
                }
            },
            State {
                name: "-45rotated"
                PropertyChanges {
                    target: rightMechineAngle
                    rotation : 45
                }
            }
        ]

        transitions: Transition {
            PropertyAnimation{
                target: rightMechineAngle
                property: "rotation"
                duration: 500
                easing.type: Easing.InOutQuad
            }
        }

        Rectangle{
            anchors.fill: parent
            color: "gold"

            Rectangle{
                width: 3
                height: parent.height * 0.8
                anchors.centerIn: parent
            }
        }
    }

    Item{
        anchors.top: rightMechineAngle.bottom
        anchors.topMargin: 80
        anchors.horizontalCenter: rightMechineAngle.horizontalCenter
        width: 400
        height: 230
        visible: !Cpp_PLC.M_530

        A_Button{
            anchors.top: parent.top
            anchors.horizontalCenter: parent.horizontalCenter
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: "45°"
            contentText_Fontsize: 35
            contentText_Bold: false

            onButtonClicked: {
                // rightMechineAngle.state = "45rotated"

            }

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(14,"1");
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(14,"0");
            }

        }

        A_Button{
            anchors.top: parent.top
            anchors.topMargin: 80
            anchors.horizontalCenter: parent.horizontalCenter
            buttonWidth: 200
            buttonHeight: 60
            contentText_Data: "90°"
            contentText_Fontsize: 35
            contentText_Bold: false

            onButtonClicked: {
                // rightMechineAngle.state = "90rotated"
            }

            onButtonPressed: {
                Cpp_PLC.write_Modbus_RTU_Coils(16,"1");
            }

            onButtonReleased: {
                Cpp_PLC.write_Modbus_RTU_Coils(16,"0");
            }

        }

        // A_Button{
        //     anchors.top: parent.top
        //     anchors.topMargin: 160
        //     anchors.horizontalCenter: parent.horizontalCenter
        //     buttonWidth: 200
        //     buttonHeight: 60
        //     contentText_Data: "-45°"
        //     contentText_Fontsize: 35
        //     contentText_Bold: false

        //     onButtonClicked: {
        //         // rightMechineAngle.state = "-45rotated"
        //     }

        // }

    }







}
